// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Components/BoxComponent.h"
#include "PaperFlipbookComponent.h"
#include "CPP_SpriteControlComponent.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PAPER2D_ACTIONGAME_API UCPP_SpriteControlComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UCPP_SpriteControlComponent();

	UPROPERTY()
	AActor* OwnerActor;

	UPROPERTY()
	APawn* PlayerPawn;
	
	UPROPERTY()
	UPaperFlipbookComponent* PFComp;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float SpriteFreezeDurationTime = 0.15f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float SpriteFreezetimeScale = 0.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float HurtFlickerDurationTime = 0.15f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float SpriteShakeDurationTime = 0.15f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float SpriteShakeFrequency = 0.015f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float SpriteShakeForce = 5.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	float CPP_MovementDir;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
	bool CPP_LockToTarget;
	
	UFUNCTION(BlueprintCallable, Category = "MyComponent")
	void CPP_HurtFlicker(UPrimitiveComponent* OtherComp);
	UFUNCTION(BlueprintCallable, Category = "MyComponent")
	void CPP_SpriteShake(UPrimitiveComponent* OtherComp);

	UFUNCTION(BlueprintCallable, Category = "MyComponent")
	void CPP_SpriteFreeze(UPrimitiveComponent* OtherComp);

	void CPP_SetFlip();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

	FVector defaultLocation;
	UMaterialInterface* defaultMat;
	FTimerHandle HurtFlickerDelayHandle;
	FTimerHandle SpriteFreezeDelayHandle;
	FTimerHandle SpriteShakeLoopHandle;
	FTimerHandle SpriteShakeDelayHandle;
	void CloseHurtFlicker();
	void CloseSpriteFreeze();
	void CloseSpriteShake();
	void SpriteShakeLoop();




public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		
};
